<?php
declare (strict_types=1);

namespace app\exam\model;

use app\common\model\BaseModel;
use think\model\concern\SoftDelete;

/**
 * 试题模型
 */
class Topic extends BaseModel
{
    use softDelete;
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'exam_question_topic';

    /**
     * 定义字段类型
     * @var [type]
     */
    protected $type = [
        'create_time'   => 'intger',
        'update_time'   => 'intger',
        'delete_time'   => 'intger'
    ];

    /**
     * append字段
     */
    protected $append = ['question_type_text'];

    /**
     * 限制机构条件
     * @Author 亓官雨树<lucky.max@foxmail.com>
     * @Date   2021-01-21
     * @param  [type]                      $query [description]
     * @return [type]                             [description]
     */
    public function scopeMhm($query)
    {
        // 机构
        $query->where('mhm_id', request()->mhm_id);
    }

    public function getQuestionTypeTextAttr($value='', $data)
    {
        $type_arr = self::getQuestionTypeArr();

        return $type_arr[$data['question_type']];
    }

    public static function getQuestionTypeArr()
    {
        return [
            1 => '单选',
            2 => '判断',
            3 => '多选',
            4 => '不定项',
            5 => '填空',
            6 => '材料',
            7 => '完形填空',
            8 => '简答题',
        ];
    }
}